<template>
  <div>
    <div class="carousel">
      <div class="swiper mySwiper">
        <div class="swiper-wrapper">
          <div class="swiper-slide" v-for="item in banners" :key="item.id">
            <img :src="item.image" alt="" />
          </div>
        </div>
        <div class="swiper-pagination"></div>
      </div>
    </div>
  </div>
</template>

<script>
import Swiper from 'swiper'
import 'swiper/swiper-bundle.min.css'
import 'swiper/modules/autoplay/autoplay.min.css'
import 'swiper/modules/pagination/pagination.min.css'
export default {
  components: {},
  props: ['data'],
  data: function () {
    return {
      banners: []
    }
  },
  created: async function () {
    this.banners = await this.data
  },
  mounted: function () {
    //
  },
  updated: function () {
    this.createSwiperObj()
  },
  methods: {
    createSwiperObj: function () {
      var myswiper = new Swiper('.mySwiper', {
        loop: true,
        autoplay: true,
        pagination: {
          el: '.swiper-pagination'
        }
      })
      return myswiper
    }
  }
}
</script>

<style lang="less" scoped>
.carousel {
  position: relative;
  height: 200px;
  margin: 0 10px;
}
.swiper {
  width: 100%;
  height: 100%;
}

.swiper-slide {
  text-align: center;
  font-size: 18px;
  background: #fff;

  /* Center slide text vertically */
  display: -webkit-box;
  display: -ms-flexbox;
  display: -webkit-flex;
  display: flex;
  -webkit-box-pack: center;
  -ms-flex-pack: center;
  -webkit-justify-content: center;
  justify-content: center;
  -webkit-box-align: center;
  -ms-flex-align: center;
  -webkit-align-items: center;
  align-items: center;
}

.swiper-slide img {
  display: block;
  width: 100%;
  height: 100%;
  object-fit: cover;
}
</style>
